/** @type {import('jest').Config} */
module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  roots: ['<rootDir>/src'],
  testMatch: [
    '**/__tests__/**/*.test.ts',
    '**/__tests__/**/*.spec.ts',
    '**/?(*.)+(spec|test).ts'
  ],
  transform: {
    '^.+\\.ts$': 'ts-jest',
  },
  collectCoverageFrom: [
    'src/**/*.ts',
    '!src/**/*.d.ts',
    '!src/index.ts',
    '!src/**/__tests__/**',
    '!src/**/*.test.ts',
    '!src/**/*.spec.ts'
  ],
  coverageDirectory: 'coverage',
  coverageReporters: ['text', 'lcov', 'html'],
  setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts'],
  globalSetup: '<rootDir>/src/__tests__/globalSetup.js',
  globalTeardown: '<rootDir>/src/__tests__/globalTeardown.js',
  maxWorkers: 1, // 强制单线程运行测试，避免并发问题
  testTimeout: 30000,
  moduleNameMapper: {
    '^@weubi/shared$': '<rootDir>/../../packages/shared/dist',
    '^@weubi/shared/(.*)$': '<rootDir>/../../packages/shared/dist/$1',
    '^@weubi/engines$': '<rootDir>/../../packages/engines/src',
    '^@weubi/engines/(.*)$': '<rootDir>/../../packages/engines/src/$1',
    '^nanoid$': '<rootDir>/src/__tests__/__mocks__/nanoid.js'
  },
  transformIgnorePatterns: [
    'node_modules/(?!(nanoid|@faker-js|date-fns)/)'
  ]
};
